<!--#include file="../nav/admin_top.php" -->
<div class="titleDiv">
	<div class="titleCaption">
		<span class="captionSpan">菜品库存</span>
		<span class="totalSpan"> <label id="captionNum"></label> </span>
	</div>
</div>
 

<div style="margin:10px auto">
	搜索：
	<select id="type_id" class="textBox">
		<option value="">-- 所有菜品类别 --</option>
		<?PHP
		foreach($rs as $v){ 
			echo '<option value="'.$v['id'].'">'.$v['type_name'].'</option>';
		}
		?> 
	</select>
	
	<select id="sale" class="textBox">
		<option value="">-- 所有供应状态 --</option>
		<option value="1">当季供应</option>
		<option value="0">非当季供应</option>
		 
	</select>
   
	<input type="text" maxlength="12" id="keywords" class="searchs" /> 
	<input type="button"  onclick="fnSearchs()" value="查 询"  />  	
	
	<input type="button" value="刷 新" onclick="grids.reload()" style="position:absolute;right:30px;" />
</div> 
<div id="grids"></div> 
<script type="text/javascript">
var url_list = '/admin_ku/index_list'; 




$().ready(function(){
	o2js.build('ymprompt'); 
	o2js.build('o2grid');
	showLoading();
	grids = new o2Grid({
		bind:'grids', 
		rowNum:1000000,
		pageCtl:{
			top:false,bottom:false
		},
		url:url_list,
		singleSelect:true,
		imgpath:'/misc/vendors/o2js/o2grid/image',
		cols:[ 
			{index:'type_name',mapping:'b.type_name',sortable:false, name:'菜品种类', width:120,func:function(val,row_index,column_name,json,R){
					return val;
				}
			},
			{index:'name',mapping:'a.name', name:'菜品名称',sortable:false, width:120,func:function(val,row_index,column_name,json,R){
					return val;
				}
			}, 
			{index:'sale',mapping:'a.sale', name:'供应状态',sortable:false, width:90,func:function(val,row_index,column_name,json,R){
					var s = '';
					if(val == '1'){ 
						s= '<span class=" ">当季供应</span>';
					}else{
						s= '<span class=" ">非当季供应</span>';
					}
					return s;
			}
			},
			{index:'nums',mapping:'a.nums', name:'当前库存量',sortable:false, width:80,func:function(val,row_index,column_name,json,R){
					return val;
				}
			}, 
			{index:'yuns',mapping:'a.yuns', name:'在途采购量',sortable:false, width:80,func:function(val,row_index,column_name,json,R){
					return val;
				}
			},
			{index:'kutotal',mapping:'a.yuns', name:'库存总和',sortable:false, width:80,func:function(val,row_index,column_name,json,R){
					return val;
				}
			}, 
			{index:'sendtotal',mapping:'a.id', name:'当前配送总数',sortable:false, width:100
			}, 
			{index:'id',mapping:'a.id', name:'库存状态',sortable:false, width:100,func:function(val,row_index,column_name,json,R){
				var cha = parseFloat(json.kutotal) - parseFloat(json.sendtotal);
				var str = '';
				if(cha < 0){
					str = '<span class="red">库存不足</span>';
				}else if(cha == 0){
					str = '<span class=" ">库存饱和</span>';
				
				}else if(cha > 0 && cha <50){
					str = '<span class="green">基本充足</span>';
					
				}else{
					str = '<span class="greenbold">充足</span>';
					
				}
				return str;
			}
			}, 
			{index:'id',mapping:'a.id', name:'操作'	, width:100,sortable:false,func:function(val,row_index,column_name,json,R){
					return    '<a href="javascript:void(0)" onclick="fnUpdate('+json.id+')"><img src="/misc/images/icos/details.gif" />  更新库存</a> ';
				}
			}
		],
		endfunc:function(obj){
			 
		}
	});
	fnSearchs();	 
	$('#keywords').keypress(function(e){
		if(e.keyCode==13||e.keyCode==10){
			fnSearchs();
		}
	}); 
	
	
	
	setInterval(function(){
		grids.reload();
	},10000);
});   
function fnSearchs(){
	grids.setBaseParams({
		keywords:encodeURIComponent($('#keywords').val()),
		type_id:$('#type_id').val(),
		sale:$('#sale').val()
	}); 
	grids.load(1); 
}

 
function fnUpdate(id){ 
	ymPrompt.close();
	ymPrompt.win({
		title:'更新库存',
		fixPosition:true,
		maxBtn:true,
		width: 700, 
		height: 400,
		iframe:{
			src:'/admin_ku/update?id='+id+'&endfunc=fnUpdateEnd'
		}
	}); 	
}
function fnUpdateEnd(){
	grids.reload();
}


</script>
<!--#include file="../nav/admin_bottom.php" -->